<?php
/**
 * QQAS - share your knowledge to the world!
 *
 * @author		xiaochong0302 <xiaochong0302@gmail.com>
 * @copyright	Copyright (c) 2011, Koogua Studio.
 * @license		http://www.qqas.org/user_guide/license.html
 * @link		http://www.qqas.org
 * @since		Version 1.0
 * @filesource
 */


class IndexAction extends AdminAction
{


    public function _initialize()
	{
		parent::_initialize();
	}


	public function index()
	{
		$this->display();
	}


	public function home()
	{
	    // 检测安装文件
	    $installFile = './Install';
        $installFileExists = $this->assign('installFileExists', file_exists($installFile));

        // 检测配置文件属性
        $configFiles = array(
            CONFIG_PATH.'config.php',
            CONFIG_PATH.'database.php',
            CONFIG_PATH.'Admin/config.php',
            CONFIG_PATH.'Home/config.php',
        );
        $comma = $writableFiles = '';
        foreach ($configFiles as $file)
        {
            if (is_writable($file))
            {
            	$writableFiles .= $comma.'"'. $file .'"';
            	$comma = ',';
            }
        }
        $this->assign('configFileWarnning', sprintf(L('home.warning_config_file_writable'), $writableFiles));
        $this->assign('configFileWritable', $writableFiles ? TRUE : FALSE);

        // 待办事项
        $Question = M('Question');
        $Answer = M('Answer');
        $Comment = M('Comment');
        $Report = M('Report');

        $modUsersCount     = $this->_User->where('user_group=4')->count();
        $modQuestionsCount = $Question->where('invisible=-1')->count();
        $modAnswersCount   = $Answer->where('invisible=-1')->count();
        $modCommentsCount  = $Comment->where('invisible=-1')->count();
        $modReportsCount   = $Report->where('is_closed=0')->count();

        $deletedQuestionsCount = $Question->where('invisible=-3')->count();
        $deletedAnswersCount   = $Answer->where('invisible=-3')->count();
        $deletedCommentsCount  = $Comment->where('invisible=-3')->count();
        $modRecycleBinCount    = $deletedQuestionsCount + $deletedAnswersCount + $deletedCommentsCount;

        $mods = array(
            'usersCount'      => intval($modUsersCount),
            'questionsCount'  => intval($modQuestionsCount),
            'answersCount'    => intval($modAnswersCount),
            'commentsCount'   => intval($modCommentsCount),
            'reportsCount'    => intval($modUsersCount),
            'recycleBinCount' => intval($modRecycleBinCount),
        );
        $this->assign('todo', $mods);

        // 在线版主
        $Model = M('UserSession');
        $map = array('user_group' => array('in', array(1,2,3)));
        $onlineModerators = $Model->where($map)->select();
        $this->assign('onlineModerators', $onlineModerators);

		$sys = array(
		    'setupTime'   => format_date(get_site_config('site_setup_time')),
			'serverTime'  => format_date('', get_site_config('default_timeformat')),
			'hostName'	  => $_SERVER['HTTP_HOST'],
			'serverPort'  => $_SERVER['SERVER_PORT'],
			'serverIP'	  => $_SERVER['SERVER_ADDR'],
			'os'		  => PHP_OS,
			'installPath' => realpath('.'),
			'safeMode'	  => !get_cfg_var('safe_mode') ? 'close' : 'open',
			'software'	  => $_SERVER['SERVER_SOFTWARE'],
			'phpVersion'  => PHP_VERSION,
			'language'	  => $_SERVER['HTTP_ACCEPT_LANGUAGE'],
			'gd'	      => function_exists('imageline') ? L('supported') : L('unsupported'),
			'gzip'	      => function_exists('ob_gzhandler') ? L('supported') : L('unsupported'),
			'zend'	      => (get_cfg_var('zend_extension_manager.optimizer_ts') || get_cfg_var('zend_extension_ts')) ? L('supported') : L('unsupported'),
		    'regGlobals'  => get_cfg_var('register_globals') ? L('supported') : L('unsupported'),
			'uploadMaxFilesize' => ini_get('file_uploads') ? ini_get('upload_max_filesize') : 0,
			'postMaxSize'       => ini_get('post_max_size') ? ini_get('post_max_size') : 0,
		);

		$Model = M();
		$dataSize  = 0;
		$indexSize = 0;
		$data = $Model->query("SHOW TABLE STATUS");
		foreach ($data as $key => $val) {
			$dataSize  += $val['Data_length'];
			$indexSize += $val['Index_length'];
		}

		$sys['mysqlVersion'] = mysql_get_server_info();
		$sys['dataSize']  = byte_format($dataSize);
		$sys['indexSize'] = byte_format($indexSize);

        $this->assign('sys', $sys);
        $this->display();
	}

}

/* End of file IndexAction.class.php */
/* Location: ./App/Lib/Action/Admincp/IndexAction.class.php */